DEBUG = YES
GPROF = NO
CPP = g++

CPPFLAGS =

ifeq ($(DEBUG),YES)
	CPPFLAGS += -W -Wall -Ddebugging -g
else
#	CPPFLAGS += -O3 -mtune=i686
#		-fno-exceptions -fomit-frame-pointer -funroll-loops
	CPPFLAGS += -O3 -march=i686 -mtune=i686 \
		-minline-all-stringops -pipe -fomit-frame-pointer -fforce-addr -finline-functions -freorder-blocks -freorder-functions -fexpensive-optimizations -falign-functions -falign-labels -falign-loops -falign-jumps -frename-registers -fweb -funit-at-a-time -funroll-loops -fprefetch-loop-arrays -ffunction-sections -fdata-sections -fbranch-target-load-optimize -fbranch-target-load-optimize2
#		-fno-exceptions
endif

ifeq ($(GPROF),YES)
	CPPFLAGS += -pg
endif

DEPENDENCY = Makefile.depend
HEADERS = $(shell ls *.h)
SOURCES = $(shell ls *.cpp | grep -v dllmain.cpp | grep -v libmod_sl.cpp)
LIBRARIES = -lncurses -lpthread -lreadline
OBJECTS = $(SOURCES:%.cpp=%.o)
ifeq ($(shell uname),CYGWIN_NT-5.1)
	BINARY = sl.exe
else
	BINARY = sl
endif

#DLLFLAGS = -shared -Wl,--dll -s -W1,-e,_cygwin_nocygwin_init@12 -mno-cygwin
#DLLLIBRARIES = -loleaut32

$(BINARY): $(DEPENDENCY) $(OBJECTS)
	$(CPP) $(CPPFLAGS) $(OBJECTS) $(LIBRARIES) -o $(BINARY)

bootstrap: $(BINARY)
	cp sl ..

clean:
	rm -f $(DEPENDENCY) $(OBJECTS) $(BINARY) $(DLLBINARY) $(ZIPFILE)

depend: $(DEPENDENCY)

$(DEPENDENCY):
#$(HEADERS) $(SOURCES) avoids generating dependency every time
	$(CPP) -MM $(SOURCES) $(CPPFLAGS) > $(DEPENDENCY)

# Include dependency file, if exists
ifeq ($(shell ls | grep $(DEPENDENCY)),$(DEPENDENCY))
include $(DEPENDENCY)
endif
